<!DOCTYPE html><html lang="en"><head><title>DeleteCreditCard</title></head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0"><meta name="groc-relative-root" content=""><meta name="groc-document-path" content="DeleteCreditCard"><meta name="groc-project-path" content="DeleteCreditCard.php"><link rel="stylesheet" type="text/css" media="all" href="assets/style.css"><script type="text/javascript" src="assets/behavior.js"></script><body><div id="meta"><div class="file-path">DeleteCreditCard.php</div></div><div id="document"><div class="segment"><div class="code"><div class="wrapper"><span class="cp">&lt;?php</span></div></div></div><div class="segment"><div class="comments"><div class="wrapper"><h1 id="delete-creditcard-sample">Delete CreditCard Sample</h1>

<p>This sample code demonstrate how you can
delete a saved credit card.
API used: /v1/vault/credit-card/{<creditCardId>}
NOTE: HTTP method used here is DELETE</p></div></div><div class="code"><div class="wrapper"><span class="k">require</span> <span class="nx">__DIR__</span> <span class="o">.</span> <span class="s1">&#39;/../bootstrap.php&#39;</span><span class="p">;</span>
<span class="k">use</span> <span class="nx">PayPal\Api\CreditCard</span><span class="p">;</span></div></div></div><div class="segment"><div class="comments"><div class="wrapper"><p>Store a mock card that can be deleted later.</p>

<h3 id="creditcard">CreditCard</h3>

<p>A resource representing a credit card that can be
used to fund a payment.</p></div></div><div class="code"><div class="wrapper"><span class="nv">$card</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">CreditCard</span><span class="p">();</span>
<span class="nv">$card</span><span class="o">-&gt;</span><span class="na">setType</span><span class="p">(</span><span class="s2">&quot;visa&quot;</span><span class="p">)</span>
  <span class="o">-&gt;</span><span class="na">setNumber</span><span class="p">(</span><span class="s2">&quot;4417119669820331&quot;</span><span class="p">)</span>
  <span class="o">-&gt;</span><span class="na">setExpireMonth</span><span class="p">(</span><span class="s2">&quot;11&quot;</span><span class="p">)</span>
  <span class="o">-&gt;</span><span class="na">setExpireYear</span><span class="p">(</span><span class="s2">&quot;2019&quot;</span><span class="p">)</span>
  <span class="o">-&gt;</span><span class="na">setCvv2</span><span class="p">(</span><span class="s2">&quot;012&quot;</span><span class="p">)</span>
  <span class="o">-&gt;</span><span class="na">setFirstName</span><span class="p">(</span><span class="s2">&quot;Joe&quot;</span><span class="p">)</span>
  <span class="o">-&gt;</span><span class="na">setLastName</span><span class="p">(</span><span class="s2">&quot;Shopper&quot;</span><span class="p">);</span></div></div></div><div class="segment"><div class="comments"><div class="wrapper"><h3 id="save-card">Save card</h3>

<p>Creates the credit card as a resource
in the PayPal vault. The response contains
an 'id' that you can use to refer to it later.
(See bootstrap.php for more on <code>ApiContext</code>)</p></div></div><div class="code"><div class="wrapper"><span class="k">try</span> <span class="p">{</span>
  <span class="nv">$card</span> <span class="o">=</span> <span class="nv">$card</span><span class="o">-&gt;</span><span class="na">create</span><span class="p">(</span><span class="nv">$apiContext</span><span class="p">);</span>
<span class="p">}</span> <span class="k">catch</span> <span class="p">(</span><span class="nx">PayPal\Exception\PPConnectionException</span> <span class="nv">$ex</span><span class="p">)</span> <span class="p">{</span>
  <span class="k">echo</span> <span class="s2">&quot;Exception:&quot;</span> <span class="o">.</span> <span class="nv">$ex</span><span class="o">-&gt;</span><span class="na">getMessage</span><span class="p">()</span> <span class="o">.</span> <span class="nx">PHP_EOL</span><span class="p">;</span>
  <span class="nb">var_dump</span><span class="p">(</span><span class="nv">$ex</span><span class="o">-&gt;</span><span class="na">getData</span><span class="p">());</span>
  <span class="k">exit</span><span class="p">(</span><span class="mi">1</span><span class="p">);</span>
<span class="p">}</span>

<span class="k">try</span> <span class="p">{</span></div></div></div><div class="segment"><div class="comments"><div class="wrapper"><h3 id="delete-card">Delete Card</h3>

<p>Lookup and delete a saved credit card.
(See bootstrap.php for more on <code>ApiContext</code>)</p></div></div><div class="code"><div class="wrapper">  <span class="nv">$creditCard</span> <span class="o">=</span> <span class="nx">CreditCard</span><span class="o">::</span><span class="na">get</span><span class="p">(</span><span class="nv">$card</span><span class="o">-&gt;</span><span class="na">getId</span><span class="p">(),</span> <span class="nv">$apiContext</span><span class="p">);</span>
  <span class="nv">$creditCard</span><span class="o">-&gt;</span><span class="na">delete</span><span class="p">(</span><span class="nv">$apiContext</span><span class="p">);</span>
<span class="p">}</span> <span class="k">catch</span> <span class="p">(</span><span class="nx">PayPal\Exception\PPConnectionException</span> <span class="nv">$ex</span><span class="p">)</span> <span class="p">{</span>
  <span class="k">echo</span> <span class="s2">&quot;Exception: &quot;</span> <span class="o">.</span> <span class="nv">$ex</span><span class="o">-&gt;</span><span class="na">getMessage</span><span class="p">()</span> <span class="o">.</span> <span class="nx">PHP_EOL</span><span class="p">;</span>
  <span class="k">exit</span><span class="p">(</span><span class="mi">1</span><span class="p">);</span>
<span class="p">}</span>
<span class="cp">?&gt;</span><span class="x"></span>
<span class="x">&lt;html&gt;</span>
<span class="x">&lt;head&gt;</span>
<span class="x">  &lt;title&gt;Delete a saved credit card&lt;/title&gt;</span>
<span class="x">&lt;/head&gt;</span>
<span class="x">&lt;body&gt;</span>
<span class="x">    &lt;p&gt; Credit Card deleted Successfully&lt;/p&gt;</span>
<span class="x">  &lt;a href=&#39;../index.html&#39;&gt;Back&lt;/a&gt;</span>
<span class="x">&lt;/body&gt;</span>
<span class="x">&lt;/html&gt;</span></div></div></div></div></body></html>
